package fy.mdm.dao;

import com.soa.eis.adapter.framework.message.IMsgObject;
import com.soa.eis.adapter.framework.message.impl.GroupRecord;
import com.soa.eis.adapter.framework.message.impl.MsgObject;
import com.soa.eis.adapter.framework.requester.IServiceRequester;
import com.soa.eis.adapter.framework.requester.impl.BaseServiceRequester;
import fy.mdm.bean.FYESupplierBean;
import fy.mdm.bean.ProviderBean;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class FYESupplierDao {
    private static Log log = LogFactory.getLog(Providerdao.class);
    private  FYESupplierBean fyeSupplierBean;


    //写入MDM数据库
    public  boolean getStateReturn() {
//		System.err.println("123");
        try {
            log.info("step001");
//			for (int i = 0, size = beans.size(); i < size; i++) {
            IServiceRequester Requester = BaseServiceRequester.getInstance();
            log.info("step002");
            List<GroupRecord> grs1 = new ArrayList<GroupRecord>();//多层用
            // 定义请求报文对象
            IMsgObject reqMo = new MsgObject(IMsgObject.MOType.initSR);
            String SourceSysID = "06004"; // 请求方(发布方)
            String ServiceID = "06001000000039";// 响应方(发布方)
            log.info("step003");
            // 获取系统时间
            Date date = new Date();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
            String format = simpleDateFormat.format(date);
            log.info("step004");
            // 对请求报文对象进行设置
            reqMo.setSourceSysID(SourceSysID); // 设置报文 请求方系统号
            reqMo.setSerialNO(format.substring(0, 8) + SourceSysID
                    + String.format("%06d", ++MaterialRequestNoTimerTask.requestNo));// 设置报文流水号,第三段表示今天发送的第几的一次报文
            reqMo.setServiceID(ServiceID); // 设置报文 提供方服务号
            reqMo.setServiceDateTime(format); // 设置报文 日期时间

            reqMo.setReqValue("BOID","MDM_EQUIPMENT_F" );
            GroupRecord gr1 = new GroupRecord();
            gr1.setName("ROW");
            log.info("step005");
            gr1.setFieldValue("MDM_CODE",fyeSupplierBean.getVenderCode());//供应商编码
            log.info("step0051"+fyeSupplierBean.getVenderCode());
            gr1.setFieldValue("Name",fyeSupplierBean.getVenderName());//供应商名称
            log.info("step0052"+fyeSupplierBean.getVenderName());
            gr1.setFieldValue("UpdateTime", format);//修改时间
            log.info("step0053"+format);
            grs1.add(gr1);
            log.info("step006");
            reqMo.setReqGroupRecord(grs1);
//				System.err.println(grs1);
            log.info("reqMo:"+reqMo);
//				System.err.println(reqMo);
            IMsgObject respMo = null;

            respMo = Requester.execute(reqMo);//发布报文
            log.info("respMo = "+respMo);
//				System.err.println(respMo);
//				log.info("respMo:"+respMo);
//			}
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }
        return true;

    }

    public FYESupplierBean getFYESupplierBean() {
        return fyeSupplierBean;
    }

    public void setFYESupplierBean(FYESupplierBean Bean) {
        fyeSupplierBean = Bean;
    }
}
